import { Inject, Injectable } from '@nestjs/common';
import Redis from 'ioredis';

@Injectable()
export class RedisService {
  constructor(@Inject('REDIS') private readonly redis: Redis) {}

  // 设置没有过期时间
  public setValue(key: string, value: string) {
    return this.redis.set(key, value);
  }

  // 设置过期时间
  public setPexValue(key: string, value: string, pex: number = 600000) {
    return this.redis.set(key, value, 'PX', pex);
  }

  // 获取redis
  public getValue(key: string) {
    return this.redis.get(key);
  }

  // 删除redis key
  public deleteKey(key: string) {
    return this.redis.del(key);
  }
}
